/*
 * Created by SharpDevelop.
 * User: daniel
 * Date: 12/25/2006
 * Time: 4:57 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.IO;

namespace MonoDoku
{
	
	public class Main_Program
	{
		public static void Main(string[] args ){
			Board gameboard;
			
			if( args.Length != 1 ){
				Window1.init_gui( 9 );
			}else{
				gameboard = process_inputs( args[0] );
				
				Solver s = new Solver();
				
				print_grid( gameboard.get_board() );
				
				gameboard = s.solve( gameboard );
				
				print_grid( gameboard.get_board() );
			}
		}
		
		public Main_Program()
		{
			
		}
		
		public static void print_grid(Object[,] grid){
			for( int i = 0; i <= grid.GetUpperBound(1); i++ ){
				for( int j = 0; j <= grid.GetUpperBound(0); j++ ){
					Console.Write( grid[ j, i ] );
				}
				Console.WriteLine();
			}
		}
		
		public static void print_line( int[] line ){
			for(int i = 0; i < line.Length; i++){
				Console.Write( line[i] );
			}
			Console.WriteLine();
		}
		
		public static void print_grid(int[,] grid){
			for( int i = 0; i <= grid.GetUpperBound(1); i++ ){
				for( int j = 0; j <= grid.GetUpperBound(0); j++ ){
					Console.Write( grid[ j, i ] );
				}
				Console.WriteLine();
			}
		}
		
		public static Board process_inputs( string filename ){
			int[,] grid;
			int[,] groups;
			using( System.IO.StreamReader input = System.IO.File.OpenText( filename ) ){
				string s;
				string[] s2;
				
				s = input.ReadLine( );
				int dimension = int.Parse( s );
				
				grid = new int[dimension, dimension];
				groups = new int[dimension, dimension];
				
				input.ReadLine();
				
				int counter = 0;
				while( (s = input.ReadLine() ) != "--" ){
					s2 = s.Split( new char[] { '*', ' ' } );
					for( int i = 0; i < s2.Length; i++ ){
						grid[i,counter] = int.Parse( s2[i] );
					}
					counter++;
				}
				
				
				counter = 0;
				while( (s = input.ReadLine() ) != null ){
					s2 = s.Split( new char[] { '*', ' ' } );
					for( int i = 0; i < s2.Length; i++ ){
						groups[i,counter] = int.Parse( s2[i] );
					}
					counter++;
				}
				
				
				
			}
			Board toReturn = new Board( grid, groups );
			return toReturn;
		}
	}
}
